{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2023-11-19T06:28:37.849573200Z",
     "start_time": "2023-11-19T06:28:37.828065600Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "计算1970年1月1日至今的毫秒数: 1700375317\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "print(\"计算1970年1月1日至今的毫秒数:\",int(time.time()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "本地时间： Sun Nov 19 14:28:32 2023\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "local_time = time.ctime()  # 获取当前本地时间的字符串表示\n",
    "print(\"本地时间：\", local_time)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-11-19T06:28:32.603229600Z",
     "start_time": "2023-11-19T06:28:32.596182500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "开始休眠...\n",
      "休眠结束\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "print(\"开始休眠...\")\n",
    "time.sleep(2)  # 休眠2秒\n",
    "print(\"休眠结束\")\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-11-19T06:32:43.540025400Z",
     "start_time": "2023-11-19T06:32:41.523086Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "time.struct_time(tm_year=2023, tm_mon=11, tm_mday=19, tm_hour=14, tm_min=38, tm_sec=45, tm_wday=6, tm_yday=323, tm_isdst=0)\n",
      "年份： 2023\n",
      "月份： 11\n",
      "星期： 6\n",
      "小时： 14\n",
      "分钟： 38\n",
      "秒： 45\n",
      "星期几： 6\n",
      "一年中的天数： 323\n",
      "夏令时间 0\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "xtime = time.localtime()\n",
    "print(xtime)\n",
    "print(\"年份：\", xtime.tm_year)\n",
    "print(\"月份：\", xtime.tm_mon)\n",
    "print(\"星期：\", xtime.tm_wday)\n",
    "print(\"小时：\", xtime.tm_hour)\n",
    "print(\"分钟：\", xtime.tm_min)\n",
    "print(\"秒：\", xtime.tm_sec)\n",
    "print(\"星期几：\", xtime.tm_wday)\n",
    "print(\"一年中的天数：\", xtime.tm_yday)\n",
    "print(\"夏令时间\", xtime.tm_isdst)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-11-19T06:38:45.331361300Z",
     "start_time": "2023-11-19T06:38:45.320801400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "格式化时间： 2023-11-19 14:42:07\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "time_tuple = time.localtime()  # 获取本地时间元组\n",
    "formatted_time = time.strftime(\"%Y-%m-%d %H:%M:%S\", time_tuple)\n",
    "print(\"格式化时间：\", formatted_time)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-11-19T06:42:07.882506100Z",
     "start_time": "2023-11-19T06:42:07.844463500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "解析后的时间元组： time.struct_time(tm_year=2023, tm_mon=11, tm_mday=19, tm_hour=15, tm_min=30, tm_sec=0, tm_wday=6, tm_yday=323, tm_isdst=-1)\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "input_time = \"2023-11-19 15:30:00\"\n",
    "parsed_time = time.strptime(input_time, \"%Y-%m-%d %H:%M:%S\")\n",
    "print(\"解析后的时间元组：\", parsed_time)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-11-19T06:44:59.923158500Z",
     "start_time": "2023-11-19T06:44:59.907499900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
